<!-- 学社 - 服务 - 顾问建议/回复顾问 -->
<template>
  <view>
    <z-navbar :title="state.navTitle" :border-bottom="true" bg-color="#F4AE20"></z-navbar>
    <view class="px-4 py-4">
      <view class="pl-7 pb-7 bg-#f5f5f5 relative rounded-lg">
        <image class="absolute top-32 left-0 w-28 h-24 z-2 ml-4" src="/static/images/home/ic_edit.png"></image>
        <u-input v-model="state.content" type="textarea" height="450" auto-height :placeholder="state.placeholder"
          placeholder-style="color: #999; fontSize: 24rpx" :custom-style="inputStyle" :maxlength="state.maxInputNum" />
        <view class="absolute bottom-30 right-10 z-2 c-#999 text-24">{{ enteredNum }}/{{ state.maxInputNum }}</view>
      </view>
      <view class="mt-4">
        <z-file-upload ref="uploader" width="144" height="144" maxCount="6" />
      </view>
    </view>

    <!-- <view class="px-4 py-4">
      <view class="relative">
        <image class="absolute top-32 left-0 w-28 h-24 z-2 ml-4" src="/static/images/home/ic_edit.png"></image>
        <u-input v-model="state.content" type="textarea" height="450" auto-height :placeholder="state.placeholder"
          placeholder-style="color: #999; fontSize: 24rpx" :custom-style="inputStyle" :maxlength="state.maxInputNum" />
        <view class="absolute bottom-30 right-10 z-2 c-#999 text-24">{{ enteredNum }}/{{ state.maxInputNum }}</view>
      </view>
      <view class="mt-4">
        <z-file-upload ref="uploader" width="144" height="144" maxCount="6" />
      </view>
    </view> -->
    <view class="bottom-wrap-16 bg-white">
      <u-line color="#eee" />
      <view class="btn-submit" @click="onSubmit">{{ state.btnName }}</view>
    </view>
  </view>
</template>

<script setup>
import { showToast } from '@/common/util/uni';
import { refreshPrePage } from '@/common/util/util'
import { postDirectorsGiveAdvice, postDirectorsReply } from '@/common/http/module/society.js'

const uploader = ref()
const state = reactive({
  diagnosis_id: '', // 诊断id
  content: '',
  navTitle: '',
  btnName: '',
  placeholder: '',
  maxInputNum: 2000,
})
const enteredNum = computed(() => {
  return state.content.length > 2000 ? 2000 : state.content.length
})
const inputStyle = {
  // backgroundColor: '#F5F5F5',
  // padding: '32rpx 32rpx 32rpx 70rpx',
  // padding: '32rpx 32rpx 32rpx 70rpx',
  // borderRadius: '12rpx',
  marginBottom:'32rpx'
}

function onSubmit() {
  if (!state.content) {
    showToast('请填写内容', 'error')
    return
  }
  const images = uploader.value.getUploadedList()
  const postMethod = state.navTitle == '回复顾问' ? postDirectorsReply : postDirectorsGiveAdvice
  const tips = state.navTitle == '回复顾问' ? '回复成功' : '发布成功'
  postMethod({
    diagnosis_id: state.diagnosis_id,
    content: state.content,
    // content: state.content.replace(/[\r\n]/g, ""),
    slideshow: images.map(v => v.url).join(','),
  }).then(() => {
    showToast(tips)
    refreshPrePage('loadData')
    setTimeout(() => uni.navigateBack(), 600)
  })
}

onLoad((options) => {
  state.navTitle = options.navTitle
  state.btnName = options.btnName
  state.placeholder = options.placeholder
  state.diagnosis_id = options.diagnosis_id
})
</script>

<style lang="scss" scoped>
/* :deep(.u-input__textarea) {
  padding: 0rpx 0rpx 32rpx 70rpx !important;
} */
</style>
